package com.cms.controller;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.TopDocs;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cms.entity.Article;
import com.cms.service.ArticleService;
import com.cms.util.Lucene;
import com.cms.util.ResponseUtil;

import net.sf.json.JSONObject;



@Controller
@RequestMapping("/Lucene")
public class SearchController {
    
	
	/**
     * 全文搜索
     * @param searchParam 关键字
     * @param model
     * @return
     */
    @RequestMapping("/searchArticle")
    public ModelAndView searchArticle(@RequestParam(value="se_title") String se_title,Model model) {
    	System.out.println(se_title);
    	ModelAndView modelAndView = new ModelAndView();
    	Lucene logic = new Lucene();
		try {
			Long startTime = System.currentTimeMillis();
			
			List<Article> result = logic.getResult(se_title);
			
			for (Article bean : result) {
				
				System.out.println(" : bean.id " + bean.getId() + 
						" : bean.title "+ bean.getTitle()+
						":bean.content"+bean.getContent());			
			}
	
		    modelAndView.addObject("result", result);
		  
			
			modelAndView.setViewName("search");
			
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println(e.getMessage());
		}
	
    	
    	return modelAndView;

    }


}